home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 98 / CD-ROM 98.iso / infantil / tuxmath / tuxmath-2001.09.07-win32-installer.exe / src / credits.c next >
Encoding:
C/C++ Source or Header  |  2001-09-07  |  7.4 KB  |  516 lines

  1. /*
  2.   credits.c
  3.  
  4.   For TuxMath
  5.   Contains the text of the credits display, as well
  6.   as the function which displays the credits in the game window.
  7.  
  8.   by Bill Kendrick
  9.   bill@newbreedsoftware.com
  10.   http://www.newbreedsoftware.com/
  11.  
  12.  
  13.   Part of "Tux4Kids" Project
  14.   http://www.tux4kids.org/
  15.       
  16.   August 26, 2001 - September 6, 2001
  17. */
  18.  
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <SDL.h>
  24. #include "options.h"
  25. #include "images.h"
  26. #include "setup.h"
  27. #include "sounds.h"
  28.  
  29.  
  30. char * credit_text[] = {
  31.   "-TUX, OF MATH COMMAND",  /* '-' at beginning makes highlighted: */
  32.   "",
  33.   "PART OF THE 'TUX4KIDS' PROJECT",
  34.   "",
  35.   "-DESIGNED BY",
  36.   "SAM 'CRISWELL' HART",
  37.   "",
  38.   "-LEAD PROGRAMMER",
  39.   "BILL KENDRICK",
  40.   "NEW BREED SOFTWARE",
  41.   "",
  42.   "-LEAD ARTIST",
  43.   "SAM HART",
  44.   "",
  45.   "-CONTRIBUTING PROGRAMMERS",
  46.   "TBA",
  47.   "",
  48.   "-ADDITIONAL ART",
  49.   "BILL KENDRICK",
  50.   "",
  51.   "-SOUND EFFECTS",
  52.   "TBA",
  53.   "",
  54.   "-MUSIC",
  55.   "TBA",
  56.   "",
  57.   "-'TUX' CREATED BY",
  58.   "LARRY EWING",
  59.   "",
  60.   "-TESTERS",
  61.   "PETE SALZMAN",
  62.   "TBA",
  63.   "", /* The following blanks cause the screen to scroll to complete blank: */
  64.   "",
  65.   "",
  66.   "",
  67.   "",
  68.   "",
  69.   "",
  70.   "",
  71.   "",
  72.   "",
  73.   "",
  74.   "",
  75.   "",
  76.   "",
  77.   "",
  78.   "",
  79.   "",
  80.   NULL
  81. };
  82.  
  83.  
  84. /* Some simple pixel-based characters we can blit quickly: */
  85.  
  86. char chars[38][5][5] = {
  87.   {".###.",
  88.    "#..##",
  89.    "#.#.#",
  90.    "##..#",
  91.    ".###."},
  92.  
  93.   {"..#..",
  94.    ".##..",
  95.    "..#..",
  96.    "..#..",
  97.    ".###."},
  98.  
  99.   {".###.",
  100.    "....#",
  101.    "..##.",
  102.    ".#...",
  103.    "#####"},
  104.  
  105.   {".###.",
  106.    "....#",
  107.    "..##.",
  108.    "....#",
  109.    ".###."},
  110.  
  111.   {"...#.",
  112.    "..##.",
  113.    ".#.#.",
  114.    "#####",
  115.    "...#."},
  116.  
  117.   {"#####",
  118.    "#....",
  119.    "####.",
  120.    "....#",
  121.    "####."},
  122.  
  123.   {".###.",
  124.    "#....",
  125.    "####.",
  126.    "#...#",
  127.    ".###."},
  128.  
  129.   {"#####",
  130.    "....#",
  131.    "...#.",
  132.    "..#..",
  133.    ".#..."},
  134.  
  135.   {".###.",
  136.    "#...#",
  137.    ".###.",
  138.    "#...#",
  139.    ".###."},
  140.  
  141.   {".###.",
  142.    "#...#",
  143.    ".####",
  144.    "....#",
  145.    ".###."},
  146.  
  147.   {".###.",
  148.    "#...#",
  149.    "#####",
  150.    "#...#",
  151.    "#...#"},
  152.  
  153.   {"####.",
  154.    "#...#",
  155.    "####.",
  156.    "#...#",
  157.    "####."},
  158.   
  159.   {".###.",
  160.    "#....",
  161.    "#....",
  162.    "#....",
  163.    ".###."},
  164.   
  165.   {"####.",
  166.    "#...#",
  167.    "#...#",
  168.    "#...#",
  169.    "####."},
  170.   
  171.   {"#####",
  172.    "#....",
  173.    "###..",
  174.    "#....",
  175.    "#####"},
  176.   
  177.   {"#####",
  178.    "#....",
  179.    "###..",
  180.    "#....",
  181.    "#...."},
  182.   
  183.   {".###.",
  184.    "#....",
  185.    "#.###",
  186.    "#...#",
  187.    ".###."},
  188.   
  189.   {"#...#",
  190.    "#...#",
  191.    "#####",
  192.    "#...#",
  193.    "#...#"},
  194.   
  195.   {".###.",
  196.    "..#..",
  197.    "..#..",
  198.    "..#..",
  199.    ".###."},
  200.   
  201.   {"....#",
  202.    "....#",
  203.    "....#",
  204.    "#...#",
  205.    ".###."},
  206.   
  207.   {"#..#.",
  208.    "#.#..",
  209.    "##...",
  210.    "#.#..",
  211.    "#..#."},
  212.   
  213.   {"#....",
  214.    "#....",
  215.    "#....",
  216.    "#....",
  217.    "#####"},
  218.   
  219.   {"#...#",
  220.    "##.##",
  221.    "#.#.#",
  222.    "#...#",
  223.    "#...#"},
  224.   
  225.   {"#...#",
  226.    "##..#",
  227.    "#.#.#",
  228.    "#..##",
  229.    "#...#"},
  230.   
  231.   {".###.",
  232.    "#...#",
  233.    "#...#",
  234.    "#...#",
  235.    ".###."},
  236.   
  237.   {"####.",
  238.    "#...#",
  239.    "####.",
  240.    "#....",
  241.    "#...."},
  242.   
  243.   {".###.",
  244.    "#...#",
  245.    "#.#.#",
  246.    "#..#.",
  247.    ".##.#"},
  248.   
  249.   {"####.",
  250.    "#...#",
  251.    "####.",
  252.    "#...#",
  253.    "#...#"},
  254.   
  255.   {".###.",
  256.    "#....",
  257.    ".###.",
  258.    "....#",
  259.    ".###."},
  260.   
  261.   {"#####",
  262.    "..#..",
  263.    "..#..",
  264.    "..#..",
  265.    "..#.."},
  266.   
  267.   {"#...#",
  268.    "#...#",
  269.    "#...#",
  270.    "#...#",
  271.    ".###."},
  272.   
  273.   {"#...#",
  274.    "#...#",
  275.    ".#.#.",
  276.    ".#.#.",
  277.    "..#.."},
  278.   
  279.   {"#...#",
  280.    "#...#",
  281.    "#.#.#",
  282.    "##.##",
  283.    "#...#"},
  284.   
  285.   {"#...#",
  286.    ".#.#.",
  287.    "..#..",
  288.    ".#.#.",
  289.    "#...#"},
  290.  
  291.   {"#...#",
  292.    ".#.#.",
  293.    "..#..",
  294.    "..#..",
  295.    "..#.."},
  296.   
  297.   {"#####",
  298.    "...#.",
  299.    "..#..",
  300.    ".#...",
  301.    "#####"},
  302.   
  303.   {".....",
  304.    ".....",
  305.    ".....",
  306.    "..#..",
  307.    ".#..."},
  308.   
  309.   {"..#..",
  310.    "..#..",
  311.    ".....",
  312.    ".....",
  313.    "....."}
  314. };
  315.  
  316.  
  317. void draw_text(char * str, int offset);
  318.  
  319.  
  320. int line;
  321.  
  322.  
  323. int credits(void)
  324. {
  325.   int done, quit, scroll;
  326.   SDL_Rect src, dest;
  327.   SDL_Event event;
  328.   Uint32 last_time, now_time;
  329.   SDLKey key;
  330.   
  331.   
  332.   /* Clear window: */
  333.   
  334.   SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
  335.   
  336.   
  337.   /* Draw title: */
  338.   
  339.   dest.x = (screen->w - images[IMG_TITLE]->w) / 2;
  340.   dest.y = 0;
  341.   dest.w = images[IMG_TITLE]->w;
  342.   dest.h = images[IMG_TITLE]->h;
  343.   
  344.   SDL_BlitSurface(images[IMG_TITLE], NULL, screen, &dest);
  345.   
  346.   
  347.   /* --- MAIN OPTIONS SCREEN LOOP: --- */
  348.   
  349.   done = 0;
  350.   quit = 0;
  351.   scroll = 0;
  352.   line = 0;
  353.   
  354.   do
  355.     {
  356.       last_time = SDL_GetTicks();
  357.       
  358.       
  359.       /* Handle any incoming events: */
  360.       
  361.       while (SDL_PollEvent(&event) > 0)
  362.     {
  363.       if (event.type == SDL_QUIT)
  364.         {
  365.           /* Window close event - quit! */
  366.           
  367.           quit = 1;
  368.           done = 1;
  369.         }
  370.       else if (event.type == SDL_KEYDOWN)
  371.         {
  372.           key = event.key.keysym.sym;
  373.           
  374.           if (key == SDLK_ESCAPE)
  375.         {
  376.           /* Escape key - quit! */
  377.           
  378.           done = 1;
  379.         }
  380.         }
  381.     }
  382.  
  383.       
  384.       /* Scroll: */
  385.  
  386.       src.x = 0;
  387.       src.y = (images[IMG_TITLE]->h) + 2;
  388.       src.w = screen->w;
  389.       src.h = screen->h - (images[IMG_TITLE]->h);
  390.       
  391.       dest.x = 0;
  392.       dest.y = (images[IMG_TITLE]->h);
  393.       dest.w = src.w;
  394.       dest.h = src.h;
  395.       
  396.       SDL_BlitSurface(screen, &src, screen, &dest);
  397.  
  398.       dest.x = 0;
  399.       dest.y = (screen->h) - 2;
  400.       dest.w = screen->w;
  401.       dest.h = 2;
  402.  
  403.       SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format, 0, 0, 0));
  404.       
  405.       
  406.       scroll++;
  407.       
  408.       draw_text(credit_text[line], scroll);
  409.       
  410.  
  411.       if (scroll >= 9)
  412.     {
  413.       scroll = 0;
  414.       line++;
  415.       
  416.       if (credit_text[line] == NULL)
  417.         done = 1;
  418.     }
  419.       
  420.       
  421.       SDL_Flip(screen);
  422.       
  423.       
  424.       /* Pause (keep frame-rate event) */
  425.       
  426.       now_time = SDL_GetTicks();
  427.       if (now_time < last_time + (1000 / 20))
  428.     {
  429.       SDL_Delay(last_time + (1000 / 20) - now_time);
  430.     }
  431.     }
  432.   while (!done);
  433.   
  434.   
  435.   /* Return the chosen command: */
  436.   
  437.   return quit;
  438. }
  439.  
  440.  
  441. void draw_text(char * str, int offset)
  442. {
  443.   int i, c, x, y, cur_x, start, hilite;
  444.   SDL_Rect dest;
  445.   Uint8 r, g, b;
  446.  
  447.  
  448.   if (str[0] == '-')
  449.   {
  450.     start = 1;
  451.     hilite = 1;
  452.   }
  453.   else
  454.   {
  455.     start = 0;
  456.     hilite = 0;
  457.   }
  458.   
  459.   
  460.   cur_x = (screen->w - ((strlen(str) - start) * 18)) / 2;
  461.   
  462.   for (i = start; i < strlen(str); i++)
  463.     {
  464.       c = -1;
  465.       
  466.       if (str[i] >= '0' && str[i] <= '9')
  467.     c = str[i] - '0';
  468.       else if (str[i] >= 'A' && str[i] <= 'Z')
  469.     c = str[i] - 'A' + 10;
  470.       else if (str[i] == ',')
  471.     c = 36;
  472.       else if (str[i] == '\'')
  473.     c = 37;
  474.       
  475.       
  476.       if (c != -1)
  477.     {
  478.       for (y = 0; y < 5; y++)
  479.         {
  480.           if (hilite == 0)
  481.           {
  482.             r = 255 - ((line * y) % 256);
  483.             g = 255 / (y + 2);
  484.             b = (line * line * 2) % 256;
  485.           }
  486.           else
  487.           {
  488.         r = 128;
  489.         g = 192;
  490.         b = 255 - (y * 40);
  491.           }
  492.           
  493.           for (x = 0; x < 5; x++)
  494.         {
  495.           if (chars[c][y][x] == '#')
  496.             {
  497.               dest.x = cur_x + (x * 3);
  498.               dest.y = ((screen->h - (5 * 3)) + (y * 3) +
  499.                 (18 - offset * 2));
  500.               dest.w = 3;
  501.               dest.h = 3;
  502.               
  503.               SDL_FillRect(screen, &dest,
  504.                    SDL_MapRGB(screen->format, r, g, b));
  505.             }
  506.         }
  507.         }
  508.     }
  509.       
  510.       
  511.       /* Move virtual cursor: */
  512.       
  513.       cur_x = cur_x + 18;
  514.     }
  515. }
  516.